require 'socket'
require 'timeout'
require 'ipaddr'
include Socket::Constants

module Hosts

	PROTOCOL = ['TCP', 'UDP', 'ICMP']

	class Host

		def ipaddr
			@ipaddr
		end

		def hostname
			@hostname
		end

		def initialize(ipaddr, hostname)
			begin
				@ipaddr = ipaddr
				#raise "tester" if @ipaddr
			rescue StandardError => e
				print e
			end
			@hostname = hostname
		end
		
		def port?(port, protocol)
			#Status of port
			begin
				case Hosts::PROTOCOL.index(protocol)
					when 0 then TCPSocket.new(@ipaddr, port)
					when 1 then raise "UDP port scanning not implemented." #UDPSocket.connect(@ipaddr, port)
					when 2 then raise "ICMP is an invalid protocol for port scanning."
					else raise "Invalid protocol specified."
				end
			rescue Errno::ECONNREFUSED
				return false
			end
					
			return true
		end
		
		def traceroute
			#TCP, ICMP & UDP Traceroute
		end
		
		def ping
			#ICMP Pings
		end
		
		
		def getPort
			return 1024 + rand(64511)
		end
	end
end